package api

import (
	"gitee.com/cdsailyj/go-vpn/common/core"
	"gitee.com/cdsailyj/go-vpn/forms/index"
	"github.com/gin-gonic/gin"
)

type Setting struct {
	core.Api
}

func (i Setting) List(c *gin.Context) {
	p, err := SettingService.GetSetting()
	if err != nil {
		i.Error(c, -1, err.Error())
		return
	}
	i.Success(c, p)
}

func (i Setting) Edit(c *gin.Context) {
	var params index.Setting
	if err := c.ShouldBindJSON(&params); err != nil {
		i.Error(c, -1, err.Error())
		return
	}

	err := SettingService.SetSetting(params)
	if err != nil {
		i.Error(c, -1, err.Error())
		return
	}
	SettingService.ReloadSetting()

	v, err := SettingService.GetSetting()
	i.Success(c, v)
}
